// 使用正则表达式对时间分割
const timeRegExp = /\[(\d{2}):(\d{2})\.(\d{2,3})\]/;

const parseLyric = (lyric: string) => {
	// 以 \n 进行分割
	const lyricStrings = lyric.split('\n');
	const lyricInfo = [];
	// 处理时间
	for (const lineString of lyricStrings) {
		// 是否有符合正则验证的 没有则跳出
		const timeResult: any = timeRegExp.exec(lineString);
		if (!timeResult) continue;
		// 获取时间
		const minute = timeResult[1] * 60 * 1000;
		const second = timeResult[2] * 1000;
		const millsecond = timeResult[3].length === 2 ? timeResult[3] * 10 : timeResult[3] * 1;
		const time: number = minute + second + millsecond;
		// 获取歌词
		const lyric: string = lineString.replace(timeRegExp, '');
		// 时间 文本合并
		lyricInfo.push({ time, lyric });
	}
	return lyricInfo;
};

export default parseLyric;
